package com.example.easyscript.service.task;

import cn.hutool.extra.cglib.CglibUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.easyscript.bean.task.StatusBean;
import com.example.easyscript.entity.task.Status;
import com.example.easyscript.mapper.StatusMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;

/**
 * @author huzixian
 * @date 2023-03-08
 */
@Slf4j
@Service
public class StatusService extends ServiceImpl<StatusMapper, Status> {

    @Resource
    private StatusImageService statusImageService;

    public Map<Integer, StatusBean> getStateBeanMapByTaskId(Integer taskId) {
        List<Status> statusList = TaskLoader.loadEntityListByTaskId(taskId, this, Status.class);
        Map<Integer, StatusBean> map = statusList.stream().map(item -> {
            StatusBean statusBean = CglibUtil.copy(item, StatusBean.class);
            List<String> urls = statusImageService.getImageListByStatusId(item.getId());
            statusBean.setSignsUrl(urls);
            return statusBean;
        }).collect(Collectors.toMap(StatusBean::getOrderId, item -> item, (a,b)->a));
        return map;
    }


}
